package com.JUC.cha08.sec02;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.concurrent.atomic.AtomicReference;

public class AtomicReferenceDemo {

@Data
@AllArgsConstructor
@NoArgsConstructor
static class User{

     String UserName;
     Integer age;

}

    public static void main(String[] args) {

        AtomicReference<User> atomicReference = new AtomicReference<>();

        User z3 = new User("Z3", 18);
        User l4 = new User("L4", 88);

        atomicReference.set(z3);

        System.out.println(atomicReference.compareAndSet(z3, l4) + "\t" + atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(z3, l4) + "\t" + atomicReference.get().toString());

    }
}
